package com.example.springboot.ext;

import com.example.springboot.annotion.User;
import com.example.springboot.component.UserComponent;
import lombok.Data;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.stereotype.Component;

@Component
@Data
@User(name="cz",age=25)
public class UserInit implements InitializingBean, DisposableBean {

    private String name;
    private String email;

    private UserComponent userComponent;

    @Override
    public void destroy() throws Exception {
        if (userComponent != null) {
            userComponent = null;
        }
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        userComponent = new UserComponent();
        userComponent.init(name, email);
    }
}
